package com.wudl.schedule.controller;

import com.wudl.schedule.service.ScheduleService;
import com.wudl.schedule.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：wudl
 * @date ：Created in 2022-03-14 15:46
 * @description：调度接口
 * @modified By：
 * @version: 1.0
 */

@RestController
@RequestMapping(value = "/scheduler")
@Slf4j
@Api(tags = "任务调度监控")
@RefreshScope
public class ScheduleContorller {


    @Value("${tempurl}")
    public String tempurl;


//    @Value("${basecommon}")
//    public String basecommon;


    @Autowired
    ScheduleService   scheduleService;
    @ApiOperation(value = "查询所有任务状态数量", notes = "查询所有任务状态数量")
    @GetMapping(value = "/taskStateCount")
    public Result getTaskStateCount(@RequestParam("startDate")  String startDate, @RequestParam("endDate") String endDate) {
        log.info("根据开始时间{} 和结束时间{}获取任务的统计",startDate,endDate);
        Result taskStateCount = scheduleService.getTaskStateCount(startDate,endDate);
        return taskStateCount;
    }

    @GetMapping(value = "/processStateCount")
    public Result getProcessStateCount(@RequestParam("startDate")  String startDate, @RequestParam("endDate") String endDate) {
        log.info("根据开始时间{} 和结束时间{}获取任务的统计");
        Result taskStateCount = scheduleService.getProcessStateCount(startDate,endDate);
        return taskStateCount;
    }

    @GetMapping(value = "/defineUserCount")
    public Result getDefineUserCount(@RequestParam("projectId")  Integer projectId) {
        log.info("根据开始时间{} 和结束时间{}获取任务的统计");
        Result taskStateCount = scheduleService.getDefineUserCount(projectId);
        return taskStateCount;
    }

    /**
     * 统计命令状态
     *
     * @return
     */
    @GetMapping(value = "/commandStateCount")
    public Result getCommandStateCount() {
        System.out.println(tempurl);
//        System.out.println(basecommon);
        log.info("根据开始时间{} 和结束时间{}获取任务的统计");
        Result taskStateCount = scheduleService.getCommandStateCount();
        return taskStateCount;
    }

    /**
     * 统计队列里任务状态
     * @return
     */

    @GetMapping(value = "/queueCount")
    public Result getQueueCount() {
        log.info("根据开始时间{} 和结束时间{}获取任务的统计");
        Result taskStateCount = scheduleService.getQueueCount();
        return taskStateCount;
    }



        @GetMapping(value = "/taskInstanceLogList")
    public Result getTaskInstanceLogList() {
        log.info("根据开始时间{} 和结束时间{}获取任务的统计");
        Result taskStateCount = scheduleService.getQueueCount();
        return taskStateCount;
    }











}
